
function doScroll(divID, fixPos, parentID) {
	var obj= document.getElementById(divID);
	var objParent= document.getElementById(parentID);
	//if (divID=="subLeft") document.getElementById('display').innerHTML =((f_scrollTop()+obj.offsetHeight)+'/'+(findYPos(objParent)+objParent.offsetHeight));
	var parentPos = findYPos(objParent);
	var floorPos = parentPos+objParent.offsetHeight;
	if ( f_scrollTop()>fixPos && fixPos+obj.offsetHeight!=floorPos) {
		if (f_scrollTop()+obj.offsetHeight >= floorPos) {
			obj.style.position = 'absolute';
			obj.style.top = (floorPos-obj.offsetHeight)+'px';
		}
		else {
			if (isIE6()) {
				obj.style.position = 'absolute';
				obj.style.top = f_scrollTop()+'px';
			}
			else {
				obj.style.position = 'fixed';
				obj.style.top = '0%';
			}
		}
	}
	else {
		if (isIE6()) {
			obj.style.display = 'block';
		}
		else {
			obj.style.top = '0%';
			obj.style.position = 'relative';
		}
	}
	//setTimeout("doScroll('"+divID+"', "+fixPos+", '"+parentID+"')", 20)
}

/**
* @desc: OnBIG work banner doc 2 ben
*
* @author: namnv@onbig.net @date: 19/12/2012 @desc: Khoi tao
*/
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	easeInCubic: function (x, t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	},
	easeInQuart: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t + b;
	},
	easeOutQuart: function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	},
	easeInOutQuart: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
		return -c/2 * ((t-=2)*t*t*t - 2) + b;
	},
	easeInQuint: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t*t + b;
	},
	easeOutQuint: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t*t*t + 1) + b;
	},
	easeInOutQuint: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
		return c/2*((t-=2)*t*t*t*t + 2) + b;
	},
	easeInSine: function (x, t, b, c, d) {
		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	},
	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	},
	easeInOutSine: function (x, t, b, c, d) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInCirc: function (x, t, b, c, d) {
		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
	},
	easeOutCirc: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	},
	easeInOutCirc: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
	},
	easeInElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	},
	easeOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	},
	easeInOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
	},
	easeInBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*(t/=d)*t*((s+1)*t - s) + b;
	},
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	},
	easeInOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158; 
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	},
	easeInBounce: function (x, t, b, c, d) {
		return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
	},
	easeOutBounce: function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	},
	easeInOutBounce: function (x, t, b, c, d) {
		if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
		return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
	}
});
(function($){

	$.fn.advScroll = function(option) {
		$.fn.advScroll.option = {
			marginTop:0,
			easing:'',
			timer:400,
		};

		option = $.extend({}, $.fn.advScroll.option, option);

		return this.each(function(){
			var el = $(this);
			$(window).scroll(function(){
				t = parseInt($(window).scrollTop()) + option.marginTop;
				el.stop().animate({marginTop:t},option.timer,option.easing);
			})
		});
	};

})(jQuery)

function do_scroll($scroll_name,$scroll_l,$scroll_r){
	if (window.innerWidth || window.innerHeight){
		docwidth = window.innerWidth;
		docheight = window.innerHeight;
	}
	//IE Mozilla
	if (document.body.clientWidth || document.body.clientHeight){
		docwidth = document.body.clientWidth;
		docheight = document.body.clientHeight;
	}
	scroll_l = $($scroll_l).innerWidth();
	scroll_r = $($scroll_r).innerWidth();

	s_left = ((docwidth - 1000)/2) - scroll_l - 5;
	s_right = ((docwidth - 1000)/2) - scroll_r - 5;
	$($scroll_l).css({'left':s_left});
	$($scroll_r).css({'right':s_right});
	if (docwidth > 1024){
		(function($){
			$($scroll_name).advScroll({
				easing:'easeOutBack',
				timer:1000
			});
		})(jQuery);
	}else{
		$($scroll_name).hide();
	}
}

/*
javascript tooltip
*/
var tooltip=function(){
	var id = 'tt';
	var top = 7;
	var left = 3;
	var maxw = 312;
	var speed = 10;
	var timer = 30;
	var endalpha = 100;
	var alpha = 0;
	var tt,t,c,b,h;
	var ie = document.all ? true : false;
	
	var item = '#'+id;
	
	return{
		show:function(v,w){
			if(tt == null){
				tt = document.createElement('div');
				tt.setAttribute('id',id);
				t = document.createElement('div');
				t.setAttribute('id',id + 'top');
				c = document.createElement('div');
				c.setAttribute('id',id + 'cont');
				b = document.createElement('div');
				b.setAttribute('id',id + 'bot');
				tt.appendChild(t);
				tt.appendChild(c);
				tt.appendChild(b);
				document.body.appendChild(tt);
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=0)';
				document.onmousemove = this.pos;
			}
			tt.style.display = 'block';
			c.innerHTML = v;
			tt.style.width = w ? w + 'px' : 'auto';
			if(!w && ie){
				t.style.display = 'none';
				b.style.display = 'none';
				tt.style.width = tt.offsetWidth;
				t.style.display = 'block';
				b.style.display = 'block';
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			h = parseInt(tt.offsetHeight) + top;
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(1)},timer);
		},
		pos:function(e){
			
			var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
			var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
			
			var h_screen = window.innerHeight;
			var w_screen = window.innerWidth;
			var heightItem = $(item).innerHeight();
			var widthItem = $(item).innerWidth();
			//var topItem = (h_screen - heightItem)/2;
			var topItem = 0;
			var leftItem = 0;
			var select_x = e.clientX;
			var select_y = e.clientY;
			
			if((h_screen - heightItem)/2 > select_y){
		    	topItem = select_y;
		    }else{
			    if(select_y > heightItem){
		    		topItem = (select_y - heightItem);
			    }else{
				    if(h_screen > heightItem){
			    		topItem = (h_screen - heightItem)/2;
				    }else{
				    	topItem = 0;
				    }
			    }
		    }
		    
		    if(widthItem < (w_screen - select_x - 45)){
		    	leftItem = select_x + 30;
		    }else{
		    	leftItem = select_x - widthItem - 30;
		    }
			
			tt.style.top = topItem + 'px';
			tt.style.left = leftItem + 'px';
		},
		fade:function(d){
			var a = alpha;
			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
				var i = speed;
				if(endalpha - a < speed && d == 1){
					i = endalpha - a;
				}else if(alpha < speed && d == -1){
					i = a;
				}
				alpha = a + (i * d);
				tt.style.opacity = alpha * .01;
				tt.style.filter = 'alpha(opacity=' + alpha + ')';
			}else{
				clearInterval(tt.timer);
				if(d == -1){tt.style.display = 'none'}
			}
		},
		hide:function(){
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
		}
	};
}();

// Submit form tim kiem
function doSubmit(){	
	if (document.frmSearch.keywords.value == "Nhập từ khóa tìm kiếm") {
		alert('Từ khóa không được để trống và phải dài hơn 2 ký tự');
		document.frmSearch.keywords.focus();
		return false;
	}
	document.frmSearch.submit();
	return;
}

// Resize panel home
function resize_panel(start_pos, end_pos)
{
	intCol 	= 3;
	hMax 	= 0;
		
	for(j = start_pos; j<= end_pos; j++)
	{
		if(document.getElementById('Cate' + j ))
		{
			intH = parseInt(jQuery("#Cate" + j).height());
		}
		
		if(intH > hMax)
		{
			hMax = intH;
		}
	}
	
	for(j=start_pos; j<=end_pos; j++)
	{
		if(document.getElementById('Cate'+j))
		{
			jQuery("#Cate"+j).css({height:hMax});
		}
	}
}




